package com.jdd.modules.sdkidentifyresultpushlog.controller;

import com.jdd.common.api.vo.Result;
import com.jdd.modules.parking.entity.ParkArmInfo;
import com.jdd.modules.parking.service.IParkArmInfoService;
import com.jdd.modules.sdkidentifyresultpushlog.service.ISdkIdentifyResultPushLogService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: DaoZhaUploadMessageController
 * @Author: Jimmy
 * @Date: 2022/4/25 11:25
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "启用遥控器开闸上传消息指令")
@RestController
@RequestMapping("/remote-control")
public class DaoZhaUploadMessageController {

    @Resource
    private ISdkIdentifyResultPushLogService sdkIdentifyResultPushLogService;

    @Resource
    private IParkArmInfoService parkArmInfoService;

    @PutMapping("/openDaoZhaUploadMessages")
    private Result<Boolean> openDaoZhaUploadMessages() {
        Result<Boolean> result = new Result<>();
        try {
            //获取车场所有的车道信息
            List<ParkArmInfo> parkArmInfosByParkCode = parkArmInfoService.findParkArmInfosByParkCode();
            if (CollectionUtils.isNotEmpty(parkArmInfosByParkCode)) {
                parkArmInfosByParkCode.forEach(
                        e -> sdkIdentifyResultPushLogService.openDaoZhaUploadMessage(e)
                );
            }
            result.setResult(Boolean.TRUE);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error("启用遥控器开闸上传消息指令失败！");
            result.error500("启用遥控器开闸上传消息指令失败!");
        }
        return result;
    }


}
